package zyn_hy_login;

public class DBCommon
{
	public static String strConnectstring = ConfigurationSettings.AppSettings["ConnectionString"];

	public static void excuteSql(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = strConnectstring;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		connection.Open();
		command.ExecuteNonQuery();
		connection.Close();
	}

	public static int excuteSqlCount(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = strConnectstring;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		SqlDataAdapter adapter = new SqlDataAdapter();
		adapter.SelectCommand = command;
		DataSet dataSet = new DataSet();
		adapter.Fill(dataSet);
		int count = dataSet.Tables[0].Rows.size();
		dataSet.Clear();
		connection.Close();
		return count;
	}

	public static DataSet getDataBySql(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = strConnectstring;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		SqlDataAdapter adapter = new SqlDataAdapter();
		adapter.SelectCommand = command;
		DataSet dataSet = new DataSet();
		adapter.Fill(dataSet);
		return dataSet;
	}

	public final SqlDataReader getDataReadBySql(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = strConnectstring;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		connection.Open();
		return command.ExecuteReader(CommandBehavior.CloseConnection);
	}
}